package cn.wellt.redission.controller;

import cn.wellt.redission.domain.Resource;
import cn.wellt.redission.domain.ResourceAcquire;
import cn.wellt.redission.service.IResourceAcquireService;
import cn.wellt.redission.service.IResourceService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author caojingchen
 * @date 2021/8/23 17:39
 */
@RequiredArgsConstructor
@RequestMapping(value = "test")
public class TesterController {
    private final IResourceService resourceService;
    private final IResourceAcquireService resourceAcquireService;


    @PostMapping(value = "acquire")
    public String acquire(@RequestParam(value = "resourceId") Long resourceId, @RequestParam(value = "userId") Long userId) {
        Resource resource = resourceService.getById(resourceId);
        // 总数限制

        // 用户限制

        // 领取
        ResourceAcquire resourceAcquire = new ResourceAcquire();
        resourceAcquire.setResourceId(resourceId);
        resourceAcquire.setUserId(userId);
        resourceAcquireService.save(resourceAcquire);

        return resourceAcquire.getId().toString();
    }

}
